package leetcode.map;

import java.util.Arrays;
import java.util.HashMap;

public class Lc1657 {


    public boolean closeStrings(String word1, String word2) {
        if (word1.length() != word2.length()) return false;
        int[] w1s = new int[26];
        int[] w2s = new int[26];
        for (int i = 0; i < word1.length(); i++) {
            w1s[word1.charAt(i) - 'a']++;
            w2s[word2.charAt(i) - 'a']++;
        }
        for (int i = 0; i < w1s.length; i++) { //判断字符集是否相等
            if (w1s[i] == 0 && w2s[i] != 0 ||
                w1s[i] != 0 && w2s[i] == 0)
                return false;
        }
        Arrays.sort(w1s);
        Arrays.sort(w2s);
        return Arrays.equals(w1s, w2s);
    }

    private void exchange(char[] chars1, char c1, char c2) {
        for (int i = 0; i < chars1.length; i++) {
            if (chars1[i] == c1) chars1[i] = c2;
            else if (chars1[i] == c2) chars1[i] = c1;
        }
    }

    public static void main(String[] args) {
        Lc1657 lc1657 = new Lc1657();
        String s1 = "cabbba";
        String s2 = "abbccc";
        System.out.println(lc1657.closeStrings(s1, s2));
    }
}
